﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    /// <summary>
    /// 创建国际化字体库分类序列化数据文件
    /// </summary>
    [CreateAssetMenu(fileName = "I18NFont", menuName = "Nirvana/I18N/I18NFont")]
    public sealed class I18NFont : ScriptableObject
    {
		[Serializable]
		private struct I18NFontConfig
		{
			[SerializeField]
			[Tooltip("The target language.")]
			public I18NLanguageType Language;
			[SerializeField]
			[Tooltip("The font name for res.load,when font is null.")]
			public string fontname;
			[SerializeField]
			[Tooltip("The font asset.")]
			public Font font;
		}

		[SerializeField]
		private I18NFontConfig[] entries;

		public Font FindFont(I18NLanguageType language)
		{
			if (this.entries == null)
			{
				return null;
			}
			int i = 0;
			foreach (var f in this.entries)
			{
				if (f.Language == language)
				{
					if (f.font == null&& !string.IsNullOrEmpty(f.fontname))
					{
						this.entries[i].font = Resources.Load<Font>("Font/"+f.fontname);
						return this.entries[i].font;
					}
					return f.font;
				}
				i++;
			}
			return null;
		}
	}
}

